package com.open.rbac.config;

import java.util.List;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.open.center.jpa.converter.WebEnumConverterFactory;
import com.open.rbac.config.resolver.TokenResolver;

/**
 * Web配置
 *
 * @author Riche's
 * @since 2025/6/13
 */
@Slf4j
@RequiredArgsConstructor
@EnableSpringDataWebSupport(
        pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO
)
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    private final TokenResolver tokenResolver;

    /**
     * Web枚举转换器工厂配置
     *
     * @param registry 格式化注册器
     */
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(new WebEnumConverterFactory());
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(tokenResolver);
        log.info("创建自定义参数解析器：TokenResolver[TokenUserId]");
    }

}
